<?php

/**
 * Config layer class
 * 
 * @package DeadTouch AAC
 * @version 0.0.1
 * @author Kofel <kofels@gmail.com>
 * @copyright 2008 (C) by Kofel
 * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
 * @todo future: :D
 */
 
class configLayer {
	private $Data = array('system_version' => '0.1a');
	
	public function load()
	{
		if( !Kernel::layer('database')->pdo )
		{
			throw new KernelExeption('Why connect isn\'t done?');
		}
				foreach( Kernel::layer('database')->query('SELECT `name`, `value` FROM `cms_settings`;')->fetchAll() as $cfg )
				{
					$this->Data[ $cfg['name'] ] = $cfg['value'];
				}
		return true;
	}
	
	public function get( $name )
	{
		return $this->Data[ $name ];
	}
	
	public function __get( $name )
	{
		return $this->get( $name );
	}
	
	public function getAll()
	{
		return $this->Data;
	}
	
	public function set( $name, $value )
	{
		Kernel::layer('database')->query('UPDATE `cms_settings` SET `value`= \'' . $value . '\' WHERE `name` = \'' . $name . '\';');
	}
}
?>